home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / xinetd.2.0.6 / itox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-22  |  3.9 KB  |  188 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: itox.c,v 5.2 1992/12/01 00:46:46 panos Exp $" ;
  8.  
  9. #define EQ( s1, s2 )                    ( strcmp( s1, s2 ) == 0 )
  10.  
  11. #define NUL                                '\0'
  12. #define NULL                            0
  13. #define PRIVATE                        static
  14.  
  15. #define FIELD_WIDTH                    15
  16. #define DAEMON_DIR_OPTION            "-daemon_dir"
  17. #define TCPD_NAME                        "tcpd"
  18.  
  19. #include "sio.h"
  20. #include "str.h"
  21. #include "misc.h"
  22.  
  23. char *strchr() ;
  24.  
  25. str_h strp ;
  26.  
  27. /*
  28.  * This program works only as a filter.
  29.  * Options:
  30.  *     -daemon_dir <dir_name>    :    if you use tcpd, this option specifies the
  31.  *                                            directory where all the daemons are.
  32.  *                                            You must specify this option if you use tcpd
  33.  */
  34. int main( argc, argv )
  35.     int argc ;
  36.     char *argv[] ;
  37. {
  38.     char *s ;
  39.     int uses_tcpd ;
  40.     char *daemon_dirpath ;
  41.     void print_line() ;
  42.     char *next_word() ;
  43.  
  44.     if ( argc != 1 && argc != 3 )
  45.     {
  46.         Sprint( 2, "Usage: %s [%s dir_path]\n",
  47.                 basename( argv[ 0 ] ), DAEMON_DIR_OPTION ) ;
  48.         exit( 1 ) ;
  49.     }
  50.  
  51.     uses_tcpd = ( argc == 3 ) ;
  52.  
  53.     if ( uses_tcpd )
  54.     {
  55.         int len ;
  56.  
  57.         daemon_dirpath = argv[ 2 ] ;
  58.         len = strlen( daemon_dirpath ) ;
  59.         if ( daemon_dirpath[ len-1 ] == '/' )
  60.             daemon_dirpath[ --len ] = NUL ;
  61.     }
  62.  
  63.     strp = str_parse( (char *)0, " \t", STR_NOFLAGS, (int *)0 ) ;
  64.  
  65.     while ( s = Srdline( 0 ) )
  66.     {
  67.         char *word ;
  68.         char *p ;
  69.         char *socket_type, *protocol ;
  70.         char *service ;
  71.         int is_rpc ;
  72.  
  73.         if ( SIOLINELEN( 0 ) == 0 || s[ 0 ] == '#' )
  74.             continue ;
  75.  
  76.         str_setstr( strp, s ) ;
  77.  
  78.         service = word = next_word( "service name" ) ;
  79.  
  80.         /*
  81.          * Check if it is an RPC service
  82.          */
  83.         p = strchr( word, '/' ) ;
  84.         if ( p != NULL )
  85.             *p = 0 ;
  86.         Sprint( 1, "service %s\n{\n", word ) ;
  87.         if ( is_rpc = ( p != NULL ) )
  88.         {
  89.             print_line( "type", "RPC" ) ;
  90.             print_line( "rpc_version", p+1 ) ;
  91.         }
  92.  
  93.         socket_type = word = next_word( "socket type" ) ;
  94.         print_line( "socket_type", socket_type ) ;
  95.  
  96.         word = next_word( "protocol" ) ;
  97.         p = strchr( word, '/' ) ;
  98.         protocol = ( p == NULL ) ? word : p+1 ;
  99.  
  100.         print_line( "protocol", protocol ) ;
  101.  
  102.         word = next_word( "wait/nowait" ) ;
  103.         print_line( "wait", EQ( word, "wait" ) ? "yes" : "no" ) ;
  104.  
  105.         word = next_word( "user" ) ;
  106.         print_line( "user", word ) ;
  107.  
  108.         word = next_word( "server" ) ;
  109.         if ( EQ( word, "internal" ) )
  110.         {
  111.             /*
  112.              * We are in trouble if this is an RPC service
  113.              */
  114.             if ( is_rpc )
  115.             {
  116.                 Sprint( 2,
  117.                     "The entry for service %s will be wrong because\n", service ) ;
  118.                 Sprint( 2, "we can't handle internal RPC services\n" ) ;
  119.             }
  120.             else
  121.             {
  122.                 print_line( "type", "INTERNAL" ) ;
  123.                 print_line( "id", make_string( 3, service, "-", socket_type ) ) ;
  124.             }
  125.         }
  126.         else
  127.         {
  128.             char *server_path = word ;        /* from inetd.conf */
  129.             char *server_of_server_path = basename( server_path ) ;
  130.             char *server_name = next_word( "server name" ) ;
  131.             char *server ;                        /* for xinetd config file */
  132.  
  133.             if ( EQ( server_of_server_path, TCPD_NAME ) )
  134.             {
  135.                 if ( ! uses_tcpd )
  136.                 {
  137.                     Sprint( 2, "You must use option %s if you use %s\n",
  138.                         DAEMON_DIR_OPTION, TCPD_NAME ) ;
  139.                     exit( 1 ) ;
  140.                 }
  141.                 if ( server_name[ 0 ] == '/' )
  142.                     server = server_name ;
  143.                 else
  144.                     server = make_pathname( 2, daemon_dirpath, server_name ) ;
  145.             }
  146.             else
  147.                 server = server_path ;
  148.  
  149.             print_line( "server", server ) ;
  150.  
  151.             word = str_component( strp ) ;            /* 1st arg */
  152.             if ( word != NULL )
  153.             {
  154.                 Sprint( 1, "\t%-*s = %s", FIELD_WIDTH, "server_args", word ) ;
  155.                 while ( word = str_component( strp ) )
  156.                     Sprint( 1, " %s", word ) ;
  157.                 Sputchar( 1, '\n' ) ;
  158.             }
  159.         }
  160.  
  161.         Sprint( 1, "}\n\n" ) ;
  162.     }
  163.     Sflush( 1 ) ;
  164.     exit( 0 ) ;
  165. }
  166.  
  167.  
  168. PRIVATE void print_line( name, value )
  169.     char *name, *value ;
  170. {
  171.     Sprint( 1, "\t%-*s = %s\n", FIELD_WIDTH, name, value ) ;
  172. }
  173.  
  174.  
  175. PRIVATE char *next_word( description )
  176.     char *description ;
  177. {
  178.     char *word = str_component( strp ) ;
  179.  
  180.     if ( word == NULL )
  181.     {
  182.         Sprint( 2, "**** %s missing \n", description ) ;
  183.         exit( 1 ) ;
  184.     }
  185.     return( word ) ;
  186. }
  187.  
  188.